Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RPC API for getting rate limits information #985

Open
wants to merge 2 commits into
base: feat/rao-devnet-ready-2
Choose a base branch
from

Conversation

ales-otf
Copy link
Contributor

@ales-otf ales-otf commented Nov 15, 2024

Description

This PR adds RateLimitInfoRuntimeApi, which provides RPC methods to fetch information about rate-limited transactions. The intention behind it is to allow clients to build logic not based on request errors, but by actual values.

Related Issue(s)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run cargo fmt and cargo clippy to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@github-actions github-actions bot added the hotfix This PR needs to be merged very quickly and will likely skip testing on devnet and testnet label Nov 15, 2024
@ales-otf ales-otf changed the base branch from main to feat/rao-devnet-ready-2 November 15, 2024 21:21
@opentensor opentensor deleted a comment from github-actions bot Nov 15, 2024
@ales-otf ales-otf removed the hotfix This PR needs to be merged very quickly and will likely skip testing on devnet and testnet label Nov 15, 2024
@ales-otf ales-otf marked this pull request as ready for review November 18, 2024 16:02
@ales-otf ales-otf requested review from gztensor, orriin, sam0x17, camfairchild and unconst and removed request for unconst November 18, 2024 16:02
stakes: Compact<u64>,
}

/// Contains last blocks, when rate-limited transactions was evaluated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This design doesn't account for all of requirements:

  1. As the issue described, we need to provide the rate limit information for: "submitting weights, registering networks, and staking/unstaking (among others)", not all of these are exposed

  2. The following concern from the issue is not addressed either: "But this would be difficult if any changes are made on the chain-side later-on and would involve a level of coupling." We need to provide a consistent rate limit information across all rate-limited items. This is just a suggestion made for example, but it could be designed as follows:

  • Requests remaining this interval
  • Total requests allowed per interval
  • Next interval start

Then for interval based limits like subnet registration it just fits the design and for cool-off type of limiting it can work as "remaining requests = 0" and "Next interval start = block when cool off period ends".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, the client software needs a way to know:

  1. If it is allowed to make a request now
  2. If not, then how long does it need to wait

Copy link
Contributor Author

@ales-otf ales-otf Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found that I forgot to add NetworkRateLimit, BTW.

As I saw it, the problem is that when you deal with limits you get the error and you need to figure out whether you are allowed to perform the request without getting error - without performing an actual transaction.

"submitting weights":

There is already API for getting weight limits: SubnetInfoRuntimeApi::get_subnet_hyperparams:

  • min_allowed_weights
  • max_weights_limit
  • weights_rate_limit

"registering networks":

Regarding subnet registrations per block: SubnetInfoRuntimeApi::get_subnet_hyperparams::max_regs_per_block.

Couldn't find anything more related to network registration rate limits.

Staking/unstaking covered by two methods: RateLimitInfoRuntimeApi::get_rate_limits and
RateLimitInfoRuntimeApi::get_stakes_this_interval.

If the clients want to check whether they exceeded the quota, they check the number of stakes allowed during interval stakes and compare it to the stakes made during interval.

We can't cover all the cases and logic, but given this data clients can build the logic, which prevent from executing transactions.

@sam0x17
Copy link
Contributor

sam0x17 commented Nov 18, 2024

bit late to this but idea: what if we just provide rate limiting information in the responses to all rate-limited requests. Like tell them how close to the quota they are at all times. Then we won't have extra traffic of them constantly checking these rpcs

@ales-otf ales-otf self-assigned this Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add RuntimeAPI for Rate Limit Checks
3 participants